using System;
using System.Collections.Generic;
using System.Text;

namespace tKitchen
{
    public class Recipe
    {
        int recipeId;
        string name;
        string descr;
        RecipeCategory category;
        IList<Recipe_Ingredient> ingredients;
        IList<Step> steps;
        double rating;
        IList<RecipeComment> comments;

        #region Properties
        public int RecipeId
        {
            get { return recipeId; }
            set { recipeId = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string Descr
        {
            get { return descr; }
            set { descr = value; }
        }

        public RecipeCategory Category
        {
            get { return category; }
            set { category = value; }
        }

        public IList<Recipe_Ingredient> Ingredients
        {
            get { return ingredients; }
            set { ingredients = value; }
        }

        public IList<Step> Steps
        {
            get { return steps; }
            set { steps = value; }
        }


        public double Rating
        {
            get { return rating; }
            set { rating = value; }
        }
        public IList<RecipeComment> Comments
        {
            get { return comments; }
            set { comments = value; }
        }
        #endregion

        public Recipe()
        {
            recipeId = -1;
            ingredients = new List<Recipe_Ingredient>();
            steps = new List<Step>();
            comments = new List<RecipeComment>();
        }
        public Recipe(RecipePO recipePOIn)
        {
            recipeId = recipePOIn.RecipeId;
            ingredients = new List<Recipe_Ingredient>();
            steps = new List<Step>();
            comments = new List<RecipeComment>();


            foreach (Recipe_IngredientPO obj in recipePOIn.Ingredients)
            {
                ingredients.Add(new Recipe_Ingredient(obj));
            }
            foreach (StepPO obj in recipePOIn.Steps)
            {
                steps.Add(new Step(obj));
            }
            foreach (RecipeCommentPO obj in recipePOIn.Comments)
            {
                comments.Add(new RecipeComment(obj));
            }

            name = recipePOIn.Name;
            rating = recipePOIn.Rating;
            descr = recipePOIn.Descr;
            if (recipePOIn.Category != null)
            {
                category = new RecipeCategory(recipePOIn.Category);
            }
            else
            {
                category = null;
            }



        }

        public override string ToString()
        {
            return this.Name;
        }

        public Recipe Copy()
        {
            Recipe temp = new Recipe();
            
            if (this.category != null)
            {
                temp.Category = this.Category.Copy();
            }

            foreach (RecipeComment rc in this.Comments)
            {
                temp.Comments.Add(rc.Copy());
            }

            temp.Descr = this.Descr;

            foreach (Recipe_Ingredient ri in this.Ingredients)
            {
                temp.Ingredients.Add(ri.Copy());
            }

            temp.Name = this.Name;
            temp.Rating = this.Rating;
            temp.RecipeId = this.RecipeId;
            foreach (Step step in this.Steps)
            {
                temp.Steps.Add(step.Copy());
            }


            return temp;
        }
    }
}
